/** ansi终端色彩定义
 * @file ansicolor.hpp
 * @author Kiven Lee
 * @version 1.0
 * @date 2021-08-09
 *
 * @copyright Copyright Kivensoft (c) 2021
 *
 */
#pragma once

#ifdef _WIN32
#   include <winsock2.h>
#   include <windows.h>
#endif

#define AC_K(X) "\x1b[30m" X "\x1b[0m"
#define AC_R(X) "\x1b[31m" X "\x1b[0m"
#define AC_G(X) "\x1b[32m" X "\x1b[0m"
#define AC_Y(X) "\x1b[33m" X "\x1b[0m"
#define AC_B(X) "\x1b[34m" X "\x1b[0m"
#define AC_M(X) "\x1b[35m" X "\x1b[0m"
#define AC_C(X) "\x1b[36m" X "\x1b[0m"
#define AC_W(X) "\x1b[37m" X "\x1b[0m"

namespace ansic {
    const inline char* K = "\x1b[30m"; // 黑, black
    const inline char* R = "\x1b[31m"; // 红, red
    const inline char* G = "\x1b[32m"; // 绿, green
    const inline char* Y = "\x1b[33m"; // 黄, yellow
    const inline char* B = "\x1b[34m"; // 蓝, blue
    const inline char* M = "\x1b[35m"; // 紫, magenta
    const inline char* C = "\x1b[36m"; // 青, cyan
    const inline char* W = "\x1b[37m"; // 白, white
    const inline char* Z = "\x1b[0m";  // 重置, reset

    struct utf8_term {
        #ifdef _WIN32
        UINT _codepage;
        DWORD _mode;

        utf8_term() {
            _codepage = GetConsoleOutputCP();
            SetConsoleOutputCP(65001);

            HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
            GetConsoleMode(handle, &_mode);
            _mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
            SetConsoleMode(handle, _mode);
        }

        ~utf8_term() {
            SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), _mode);
            SetConsoleOutputCP(_codepage);
        }
        #endif // _WIN32
    };

} // namespace ansi